package com.haixiaoke.saas.enterprise.order.controller;

import com.haixiaoke.saas.common.annotation.RepeatSubmit;
import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.utils.poi.ExcelUtil;
import com.haixiaoke.saas.order.domain.PayType;
import com.haixiaoke.saas.order.service.IPayTypeService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 押付方式Controller
 *
 * @author xiaolong
 * @date 2023-10-25
 */
@RestController
@RequestMapping("/enterprise/order/payType")
public class EnterprisePayTypeController extends BaseController {
    @Autowired
    private IPayTypeService payTypeService;

    /**
     * 查询押付方式列表
     */
    // @PreAuthorize("@ss.hasPermi('business:type:list')")
    @GetMapping("/list")
    public AjaxResult list(PayType payType) {
        List<PayType> list = payTypeService.selectPayTypeList(payType);
        return AjaxResult.success(list);
    }

    /**
     * 导出押付方式列表
     */
    @PreAuthorize("@ss.hasPermi('business:type:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PayType payType) {
        List<PayType> list = payTypeService.selectPayTypeList(payType);
        ExcelUtil<PayType> util = new ExcelUtil<PayType>(PayType.class);
        util.exportExcel(response, list, "押付方式数据");
    }

    /**
     * 获取押付方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(payTypeService.selectPayTypeById(id));
    }

    /**
     * 新增押付方式
     */
    @PreAuthorize("@ss.hasPermi('business:type:add')")
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody PayType payType) {
        return toAjax(payTypeService.insertPayType(payType));
    }

    /**
     * 修改押付方式
     */
    @PreAuthorize("@ss.hasPermi('business:type:edit')")
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@RequestBody PayType payType) {
        return toAjax(payTypeService.updatePayType(payType));
    }

    /**
     * 删除押付方式
     */
    @PreAuthorize("@ss.hasPermi('business:type:remove')")
    @DeleteMapping("/{ids}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(payTypeService.deletePayTypeByIds(ids));
    }
}
